package com.sanshow.charging.util;

import android.os.Build;
import android.text.TextUtils;

import com.blankj.utilcode.util.StringUtils;

import java.lang.reflect.Method;

public class DeviceUtil {

    public static String getSerialNumber(){
        // return "000050";
        String serial = null;
        try {
            Class<?> c =Class.forName("android.os.SystemProperties");
            Method get =c.getMethod("get", String.class);
            serial = (String)get.invoke(c, "ro.serialno"); //
            if(StringUtils.isEmpty(serial)){
                serial = (String)get.invoke(c, "ro.boot.serialno");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return serial;

    }

    public static String getSerialNo() {
        //return "8888888888888";
        if(!TextUtils.isEmpty(Build.SERIAL) && !"unknown".equalsIgnoreCase(Build.SERIAL)) {
            return Build.SERIAL;
        }
        try {
            Class<?> claz = Class.forName("android.os.Build");
            Method method = claz.getMethod("getSerial");
            String serial = (String) method.invoke(null);
            return TextUtils.isEmpty(serial) || "unknown".equalsIgnoreCase(serial) ? "" : serial.toUpperCase();
        } catch (Exception e) {
            return "";
        }
    }

    public static String getSerialNumber1(){
        String serialNumber = "";
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            serialNumber = Build.getSerial();
        }else {
            serialNumber = Build.SERIAL;
        }
        return serialNumber;
    }

}
